package com.niit.sum.schoolsum;


import com.niit.bean.StudentCountBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SchoolSumMapper extends Mapper<LongWritable, Text, Text, StudentCountBean> {

    Text outKey = new Text();
    StudentCountBean outValue = new StudentCountBean();

    /**
     * 1、重写map父类方法：map回车
     */
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        /**
         * 2、读取一行数据进行切割
         */
        String[] fields = value.toString().split(",");


        String school = fields[1];

        long ActiveDays =Long.parseLong(fields[10]);  //活跃天数
        long StudentsNum =Long.parseLong(fields[6]);
        if (school == null || school.equals("未知") || school.equals("")) {
            return; // 跳过这个记录，不进行处理
        }
        outKey.set(school);
        outValue.set(ActiveDays ,StudentsNum);
        context.write(outKey, outValue);
    }
}
